<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0 auto;
        }

        .box {
            border: 1px solid black;
            background-color: yellow;
            position: absolute;
        }
        
        .box1 {
            top: 30px;
            width: 100px;
            height: 100px;
        }
        
        .box2 {
            height: 100px;
            width: 100px;
            top: 200px;
        }
    </style>
</head>
<body>
    <div class="box box1">box1</div>
    <div class="box box2">box2</div>
    <script>
        function moveTo(iterm, len) {
            iterm.timer = setInterval(function() {
                iterm.style.left = iterm.offsetLeft + 5 + 'px';
                if (iterm.offsetLeft >= len) {
                    clearInterval(iterm.timer);
                }
            }, 30);
        }
        var box1 = document.querySelector('.box1');
        var box2 = document.querySelector('.box2');
        moveTo(box1, 300);
        moveTo(box2, 400);
    </script>
</body>
</html>